﻿package org.leles.engines.simon 
{
	
	/**
	 * ...
	 * @author Bruno Leles
	 */
	public class SimonEngine extends SimonEngineObject
	{
		protected var numNotes:int;
		protected var state:int;
		
		protected var finalLevel:int = int.MAX_VALUE;
		
		protected var currentLevel:int;
		protected var currentLevelSequence:Array;
		
		public function SimonEngine(numNotes:int = 4) 
		{
			super();
			state = 0;
			numNotes = notes;
		}
		
		public function gameStart(level:int = 1):void 
		{
			if ( level < 1 ) throw new Error( "Level must be greather than 0" );
			currentLevel = level;
			
			startLevel();
			// event ( game start );
		}
		
		private function startLevel():void
		{
			//
			currentLevelSequence.length = 0;
			//
			var possibleValues:Array = [];
			var i:int;
			
			for (i = 0; i < numNotes; i++) possibleValues[i] = i;
			
			while ( possibleValues.length > 0 )
			{
				i = (Math.random() * possibleValues.length) as int;
				currentLevelSequence.push( possibleValues.splice(i, 1) );
			}
			// event ( start Level );
		}
		
		private function gameOver():void
		{
			//
		}
		
		private function nextLevel():void
		{
			if ( (currentLevel++) == finalLevel )	gameOver();
			else									startLevel();
			// event next Level
		}
		
		public function hitNote(note:int):void 
		{
			if ( currentLevelSequence[0] == note )
			{
				currentLevelSequence.shift();
				// event right note
			}else
			{
				gameOver();
			}
		}
	}
	
}